<script setup lang="tsx">
// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 模块导入 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

import { computed, reactive, toRefs, watch } from 'vue';
import dayjs from 'dayjs';
import { $t } from '@/locales';
import { useNaiveForm } from '@/hooks/common/form';
import {
  fetchAddDmRecycleUser,
  fetchGetMyUniqueProvinceCityCounty,
  fetchUpdateDmRecycleUser,
  getUserOrgInfo
  // fetchUpdateRecycle,
} from '@/service/api';
import { useAuth } from '@/hooks/business/auth';

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 组件名称 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

defineOptions({
  name: 'DimoRecycleOperateModal'
});

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 组合式函数 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

const { validate, restoreValidation } = useNaiveForm();

const { currentOrgPosition, userInfo } = useAuth();

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 父子传参 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

interface Props {
  /** the type of operation */
  operateType: OperateType;
  /** the edit row data */
  rowData?: Api.Dimo.DmRecycleUser | null;
}

const props = defineProps<Props>();

interface Emits {
  (e: 'submitted'): void;
}

const emit = defineEmits<Emits>();

const visible = defineModel<boolean>('visible', {
  default: false
});

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 框架模型 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

export type OperateType = NaiveUI.TableOperateType | 'view';

const isAdd = computed(() => props.operateType === 'add');

const isEdit = computed(() => props.operateType === 'edit');

const isView = computed(() => props.operateType === 'view');

const addKey = computed(() => `DMRECYCLEUSER${userInfo()?.userName}ADD`);

const editKey = computed(() => `DMRECYCLEUSER${userInfo()?.userName}EDIT${props.rowData?.id}`);

const title = computed(() => {
  const titles: Record<OperateType, string> = {
    add: $t('common.add'),
    edit: $t('common.edit'),
    view: '查看'
  };
  return `【${titles[props.operateType]}】农用薄膜使用回收情况入户抽样调查表`;
});

type Model = Api.Dimo.DmRecycleUser;

const model: Model = reactive(createDefaultModel());

function createDefaultModel(): Model {
  return {
    id: '',
    createUser: '',
    createTime: '',
    updateUser: '',
    updateTime: '',
    tenantId: '',
    orgId: '',
    positionId: '',
    surveyPointId: '',
    reportDate: dayjs().format('YYYY-MM-DD HH:mm:ss'),
    reportPerson: '',
    reportPersonContactInfo: '',
    investPerson: '',
    investPersonContactInfo: '',
    countyAuthStatus: false,
    countyAuthDate: '',
    countyAuthUserId: 0,
    cityAuthStatus: false,
    cityAuthDate: '',
    cityAuthUserId: 0,
    provinceAuthStatus: false,
    provinceAuthDate: '',
    provinceAuthUserId: 0,
    comment: '',
    cultivatedArea: 0,
    sownArea: 0,
    farmhouseName: '',
    farmhouseType: 1,
    cropType: 1,
    averageRainfall: 0,
    sunshineHours: 0,
    frostFreePeriod: 0,
    irrigationMethod: 1,
    pmApplyCoverageArea: 0,
    pmApplyCurrentUsage: 0,
    pmApplyFirstYear: 0,
    pmApplyLastRenewYear: 0,
    pmApplyContinueThisYear: true,
    pmApplyReplaceThisYear: true,
    pmRecycleTotalUsage: 0,
    pmRecycleContinuedUsage: 0,
    pmRecycleReplacedQuantity: 0,
    pmDisposeNextYearCover: 0,
    pmDisposeRuralLifeRecycle: 0,
    pmDisposeWasteDisposalStation: 0,
    pmDisposeWasteRecycleEnterprise: 0,
    pmDisposeOtherMethods: 0,
    dmApplyFirstYear: 0,
    dmApplyCoverYears: 0,
    dmApplyCoverArea: 0,
    dmApplyStandardFilm: 0,
    dmApplyThickHighStrength: 0,
    dmApplyBioDegradable: 0,
    dmApplyUsageAmount: 0,
    dmApplyStandardUsage: 0,
    dmApplyThickUsage: 0,
    dmApplyBioUsage: 0,
    dmApplyCoverMethod: 1,
    dmApplyFilmCycle: 0,
    dmApplyManufacturerName: '',
    dmApplyManufacturerTel: '',
    dmApplyFilmThickness: 0,
    dmApplyFilmWidth: 0,
    dmApplyFilmColor: 1,
    dmRecycleManualArea: 0,
    dmRecycleManualCost: 0,
    dmRecycleMachineArea: 0,
    dmRecycleMachineCost: 0,
    dmRecycleCompoundArea: 0,
    dmRecycleCompoundCost: 0,
    dmRecycleNonRecycleArea: 0,
    dmRecycleResidueAmount: 0,
    dmDisposeRuralGarbage: 0,
    dmDisposeWasteFilmStation: 0,
    dmDisposeRecycleEnterprise: 0,
    dmDisposeFieldStack: 0,
    dmDisposeNearbyBurn: 0,
    dmDisposeNearbyBury: 0,
    dmDisposeRecycle: 0,
    dmDisposeRural: 0,
    dmDisposeOtherMethod: 0,
    wasteAgriFilmStation: true,
    stationRecyclePrice: 0,
    wasteAgriFilmEnterprise: true,
    enterpriseRecyclePrice: 0,
    township: '',
    village: '',
    provinceCityCountyInfo: {
      provinceId: '',
      provinceName: '',
      cityId: '',
      cityName: '',
      countyId: '',
      countyName: ''
    },
    dmRecycleUserDetails: [createRecyclePilot()],
    orgCode: '',
    seqId: '',
    reportUnit: ''
  };
}

function createRecyclePilot() {
  return {
    cropName: '',
    filmQuantity: 0,
    fieldCoverage: 0
  };
}

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 业务模型 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

// const orgType = ref<string>(currentOrgPosition()?.orgType || '');

const state = reactive({
  farmersList: [
    { value: 1, label: '普通农户' },
    { value: 2, label: '种植大户' },
    { value: 3, label: '家庭农场' },
    { value: 4, label: '农产企业' },
    { value: 5, label: '农民专业合作社' },
    { value: 6, label: '其他' }
  ],
  cropType: [
    { value: 1, label: '棚膜作物' },
    { value: 2, label: '露天覆膜作物' },
    { value: 3, label: '棚膜+露天覆膜作物' }
  ],
  irrigation: [
    { value: 1, label: '滴灌' },
    { value: 2, label: '沟灌' },
    { value: 3, label: '畦灌' },
    { value: 4, label: '喷灌' },
    { value: 5, label: '无灌溉' }
  ],
  getCropType: new Map([
    [0, ''],
    [1, '棚膜作物'],
    [2, '露天覆膜作物'],
    [3, '棚膜+露天覆膜作物']
  ]),
  getIrrigation: new Map([
    [0, ''],
    [1, '滴灌'],
    [2, '沟灌'],
    [3, '畦灌'],
    [4, '喷灌'],
    [5, '喷灌'],
    [6, '无灌溉']
  ]),
  getFarmersList: new Map([
    [0, ''],
    [1, '普通农户'],
    [2, '种植大户'],
    [3, '家庭农场'],
    [4, '农产企业'],
    [5, '农民专业合作社'],
    [6, '其他']
  ]),
  getDmApplyFilmColor: new Map([
    [0, ''],
    [1, '白色'],
    [2, '黑色'],
    [3, '其他']
  ])
});

const { farmersList, getFarmersList, cropType, irrigation, getCropType, getIrrigation, getDmApplyFilmColor } = toRefs(state);
// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 框架方法 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

function handleInitModel() {
  Object.assign(model, createDefaultModel());

  let localData = null;
  if (props.operateType === 'add') {
    localData = localStorage.getItem(addKey.value);
  } else if (props.operateType === 'edit') {
    localData = localStorage.getItem(editKey.value);
  }

  if (localData) {
    window.$dialog?.info({
      title: $t('common.tip'),
      content: '检测到上次您有未保存的数据，是否继续使用该数据进行操作?',
      positiveText: $t('common.confirm'),
      negativeText: $t('common.cancel'),
      onPositiveClick: () => {
        console.log('继续使用上次数据', JSON.parse(localData));
        Object.assign(model, JSON.parse(localData));
      },
      onNegativeClick: () => {
        if (isAdd.value) {
          localStorage.removeItem(addKey.value);
        } else if (isEdit.value) {
          localStorage.removeItem(editKey.value);
        }
        handleAEV();
      }
    });
  } else {
    handleAEV();
  }
}

function handleAEV() {
  if (props.operateType === 'add') {
    getUserOrg();
    model.reportPerson = userInfo()?.realName || '';
    fetchGetMyUniqueProvinceCityCounty().then(({ error, data }) => {
      if (!error && data) {
        model.provinceCityCountyInfo = data;
        model.orgId = data.countyId ?? data.cityId ?? data.provinceId;
      }
    });
  } else if (['edit', 'view'].includes(props.operateType) && props.rowData) {
    const d: Model = JSON.parse(JSON.stringify(props.rowData));
    console.log(d.dmRecycleUserDetails, '读取列表数据');
    d.reportDate = dayjs(d.reportDate).format('YYYY-MM-DD HH:mm:ss');
    Object.assign(model, d);
    console.log(model.dmRecycleUserDetails, '替换数据');
  }
}

function closeModal() {
  visible.value = false;
}

async function handleSubmit() {
  await validate();
  const func = isAdd.value ? fetchAddDmRecycleUser : fetchUpdateDmRecycleUser;
  if (isAdd.value) {
    model.orgId = currentOrgPosition()?.orgId || '';
    model.positionId = currentOrgPosition()?.positionId || '';
  }
  console.log(model, '提交时数据');

  const { error, data } = await func(model);
  if (!error && data) {
    window.$message?.success(isAdd.value ? $t('common.addSuccess') : $t('common.updateSuccess'));
    if (isAdd.value) {
      localStorage.removeItem(addKey.value);
    } else if (isEdit.value) {
      localStorage.removeItem(editKey.value);
    }
    closeModal();
    emit('submitted');
  }
}

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 业务方法 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

/**
 *  获取用户组织信息
 */
function getUserOrg() {
  getUserOrgInfo().then((res) => {
    const { surveyPointId, nextSeqId, orgCode } = res.data;
    console.log(surveyPointId, nextSeqId, orgCode);
    model.surveyPointId = surveyPointId;
    model.seqId = nextSeqId;
    model.orgCode = orgCode;
  });
}

function plusPilot(index: number) {
  if (model.dmRecycleUserDetails.length === index + 1) {
    model.dmRecycleUserDetails.push(createRecyclePilot());
  } else {
    model.dmRecycleUserDetails.splice(index + 1, 0, createRecyclePilot());
  }
}

function reducePilot(index: number) {
  model.dmRecycleUserDetails.splice(index, 1);
}

function tempSave() {
  if (isAdd.value) {
    localStorage.removeItem(addKey.value);
    const plainObject = JSON.parse(JSON.stringify(model));
    localStorage.setItem(addKey.value, JSON.stringify(plainObject));
  } else if (isEdit.value) {
    const plainObject = JSON.parse(JSON.stringify(model));
    localStorage.setItem(editKey.value, JSON.stringify(plainObject));
  }
  window.$message?.success('临时保存成功');
}

// +++++++++++++++++++++++++++++++++++++++++++++++
// ---------- 框架生命周期 ----------
// +++++++++++++++++++++++++++++++++++++++++++++++

watch(visible, () => {
  if (visible.value) {
    handleInitModel();
    restoreValidation();
  }
});
</script>

<template>
  <NModal v-model:show="visible" :title="title" preset="card" class="w-1280px" :close-on-esc="false" :mask-closable="false">
    <div class="info">
      <div class="title-info">
        <NSpace v-if="!isView">
          <div class="w-300px">
            <NInput v-model:value="model.surveyPointId" type="text" disabled>
              <template #prefix>监测点编号：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.provinceCityCountyInfo.cityName" type="text" disabled>
              <template #prefix>市（州）：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.provinceCityCountyInfo.countyName" type="text" disabled>
              <template #prefix>县（市、区）：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.township" type="text">
              <template #prefix>乡（镇）：</template>
            </NInput>
          </div>
          <div class="w-300px">
            <NInput v-model:value="model.village" type="text">
              <template #prefix>村：</template>
            </NInput>
          </div>
        </NSpace>
        <NSpace v-else>
          <span class="mr-60px">
            <b>填报单位：</b>
            {{ model.surveyPointId }}
          </span>
          <span class="mr-60px">
            <b>市：</b>
            {{ model.provinceCityCountyInfo.cityName }}
          </span>
          <span class="mr-60px">
            <b>县：</b>
            {{ model.provinceCityCountyInfo.countyName }}
          </span>
          <span class="mr-60px">
            <b>镇（乡）：</b>
            {{ model.township }}
          </span>
          <span class="mr-60px">
            <b>村：</b>
            {{ model.village }}
          </span>
          <span>
            <b>填报日期：</b>
            {{ dayjs(model.reportDate).format('YYYY-MM-DD') }}
          </span>
        </NSpace>
      </div>
      <div class="table-info">
        <table>
          <thead>
            <tr>
              <th colspan="5">指标名称</th>
              <th class="w-80px text-center">单位</th>
              <th class="w-200px">指标值</th>
            </tr>
          </thead>
          <tbody>
            <!-- 基本情况 -->
            <tr>
              <td rowspan="9">基本情况</td>
              <td colspan="4">农户姓名</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NInput v-model:value="model.farmhouseName" type="text" size="small" />
              </td>
              <td v-else class="text-right">{{ model.farmhouseName }}</td>
            </tr>
            <tr>
              <td colspan="4">农户类型</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NRadioGroup v-model:value="model.farmhouseType">
                  <NRadio v-for="item in farmersList" :key="item.value" :value="item.value" :label="item.label" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ getFarmersList.get(model.farmhouseType) }}</td>
            </tr>
            <tr>
              <td colspan="4">耕地面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.cultivatedArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.cultivatedArea }}</td>
            </tr>
            <tr>
              <td colspan="4">农作物播种面积</td>
              <!-- <td colspan="2">亩</td> -->
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.sownArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.sownArea }}</td>
            </tr>
            <tr>
              <td colspan="4">作物类型</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NRadioGroup v-model:value="model.cropType">
                  <NRadio v-for="item in cropType" :key="item.value" :value="item.value" :label="item.label" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ getCropType.get(model.cropType) }}</td>
            </tr>
            <tr>
              <td colspan="4">平均降雨量</td>
              <td class="text-center">毫米/年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.averageRainfall" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.averageRainfall }}</td>
            </tr>
            <tr>
              <td colspan="4">日照时数</td>
              <td class="text-center">小时/年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.sunshineHours" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.sunshineHours }}</td>
            </tr>
            <tr>
              <td colspan="4">无霜期</td>
              <td class="text-center">天/年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.frostFreePeriod" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.frostFreePeriod }}</td>
            </tr>
            <tr>
              <td colspan="4">灌溉方式</td>
              <td class="text-center">天/年</td>
              <td v-if="!isView">
                <NRadioGroup v-model:value="model.irrigationMethod">
                  <NRadio v-for="item in irrigation" :key="item.value" :value="item.value" :label="item.label" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ getIrrigation.get(model.irrigationMethod) }}</td>
            </tr>
            <!-- 棚膜使用回收情况 -->
            <tr>
              <td rowspan="15">棚膜使用回收情况</td>
              <td rowspan="7">应用情况</td>
            </tr>
            <tr>
              <td colspan="3">覆盖面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmApplyCoverageArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmApplyCoverageArea }}</td>
            </tr>
            <tr>
              <td colspan="3">使用量（当年正在使用的全部棚膜）</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmApplyCurrentUsage" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmApplyCurrentUsage }}</td>
            </tr>
            <tr>
              <td colspan="3">首次用膜年份</td>
              <td class="text-center">*年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmApplyFirstYear" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmApplyFirstYear }}</td>
            </tr>

            <tr>
              <td colspan="3">最近一次覆新膜年份</td>
              <td class="text-center">*年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmApplyLastRenewYear" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmApplyLastRenewYear }}</td>
            </tr>
            <tr>
              <td colspan="3">所覆棚膜今年是否继续使用</td>
              <td class="text-center">是/否</td>
              <td v-if="!isView">
                <NRadioGroup v-if="!isView" v-model:value="model.pmApplyContinueThisYear">
                  <NRadio :value="true" label="是" />
                  <NRadio :value="false" label="否" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ model.pmApplyContinueThisYear ? '是' : '否' }}</td>
            </tr>
            <tr>
              <td colspan="3">今年棚膜是否更换新膜</td>
              <td class="text-center">是/否</td>
              <td v-if="!isView">
                <NRadioGroup v-if="!isView" v-model:value="model.pmApplyReplaceThisYear">
                  <NRadio :value="true" label="是" />
                  <NRadio :value="false" label="否" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ model.pmApplyReplaceThisYear ? '是' : '否' }}</td>
            </tr>

            <!-- 地膜使用回收情况 -->
            <tr>
              <td rowspan="3">回收情况</td>
              <td rowspan="3">回收量</td>
              <td colspan="2">当年正在使用的全部棚膜量（总）</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmRecycleTotalUsage" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmRecycleTotalUsage }}</td>
            </tr>
            <tr>
              <td colspan="2">其中，之前投入使用且今年仍在继续使用的棚膜量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmRecycleContinuedUsage" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmRecycleContinuedUsage }}</td>
            </tr>
            <tr>
              <td colspan="2">其中，当年被替换下来的旧膜量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmRecycleReplacedQuantity" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmRecycleReplacedQuantity }}</td>
            </tr>
            <tr>
              <td rowspan="5">处置情况</td>
              <td colspan="3">次年继续棚膜覆膜</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmDisposeNextYearCover" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmDisposeNextYearCover }}</td>
            </tr>
            <tr>
              <td colspan="3">清运至农村生活垃圾回收处置点</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmDisposeRuralLifeRecycle" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmDisposeRuralLifeRecycle }}</td>
            </tr>
            <tr>
              <td colspan="3">回收至废旧农膜回收处置站（点）</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmDisposeWasteDisposalStation" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmDisposeWasteDisposalStation }}</td>
            </tr>
            <tr>
              <td colspan="3">回收至废旧农膜回收利用企业</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmDisposeWasteRecycleEnterprise" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmDisposeWasteRecycleEnterprise }}</td>
            </tr>
            <tr>
              <td colspan="3">其他处置方式</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.pmDisposeOtherMethods" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.pmDisposeOtherMethods }}</td>
            </tr>
            <!-- 工作开展情况 -->
            <template v-for="(row, index) in model.dmRecycleUserDetails" :key="index">
              <tr>
                <td v-if="index === 0" :rowspan="model.dmRecycleUserDetails.length * 3 + 31">地膜使用回收情况</td>
                <td v-if="index === 0" :rowspan="model.dmRecycleUserDetails.length * 3 + 17">应用情况</td>
                <td rowspan="3">
                  <div>第{{ index + 1 }}茬</div>
                  <div v-if="!isView">
                    <NSpace>
                      <NButton ghost circle type="primary" size="tiny" @click="plusPilot(index)">
                        <template #icon>
                          <icon-carbon:add />
                        </template>
                      </NButton>
                      <NButton v-if="model.dmRecycleUserDetails.length > 1" ghost circle type="primary" size="tiny" @click="reducePilot(index)">
                        <template #icon>
                          <icon-carbon:close />
                        </template>
                      </NButton>
                    </NSpace>
                  </div>
                </td>
                <td colspan="2">覆膜作物名称</td>
                <td class="text-center">--</td>
                <td v-if="!isView">
                  <NInput v-model:value="row.cropName" clearable size="small" />
                </td>
                <td v-else class="text-right">{{ row.cropName }}</td>
              </tr>
              <tr>
                <td colspan="2">覆膜量</td>
                <td class="text-center">千克</td>
                <td v-if="!isView">
                  <NInputNumber v-model:value="row.filmQuantity" clearable :precision="2" size="small" />
                </td>
                <td v-else class="text-right">{{ row.filmQuantity }}</td>
              </tr>
              <tr>
                <td colspan="2">田间覆膜比例</td>
                <td class="text-center">%</td>
                <td v-if="!isView">
                  <NInputNumber v-model:value="row.fieldCoverage" clearable :precision="2" size="small" />
                </td>
                <td v-else class="text-right">{{ row.fieldCoverage }}</td>
              </tr>
            </template>

            <tr>
              <td colspan="3">首次覆膜年份</td>
              <td class="text-center">*年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyFirstYear" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyFirstYear }}</td>
            </tr>
            <tr>
              <td colspan="3">覆膜年限</td>
              <td class="text-center">*年</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyCoverYears" clearable :precision="1" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyCoverYears }}</td>
            </tr>
            <tr>
              <td rowspan="4">覆膜面积</td>
              <td colspan="2">覆膜面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyCoverArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyCoverArea }}</td>
            </tr>
            <tr>
              <td colspan="2">其中，标准地膜</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyStandardFilm" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyStandardFilm }}</td>
            </tr>
            <tr>
              <td colspan="2">其中，加厚高强度地膜</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyThickHighStrength" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyThickHighStrength }}</td>
            </tr>
            <tr>
              <td colspan="2">其中，全生物降解地膜</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyBioDegradable" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyBioDegradable }}</td>
            </tr>
            <tr>
              <td rowspan="5">使用量</td>
              <td colspan="2">使用量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyUsageAmount" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyUsageAmount }}</td>
            </tr>
            <tr>
              <td colspan="2">其中，标准地膜</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyStandardUsage" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyStandardUsage }}</td>
            </tr>
            <tr>
              <td colspan="2">其中，加厚高强度地膜</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyThickUsage" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyThickUsage }}</td>
            </tr>
            <tr>
              <td colspan="2">其中，全生物降解地膜</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyBioUsage" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyBioUsage }}</td>
            </tr>
            <tr>
              <td colspan="2">覆膜方式</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NRadioGroup v-if="!isView" v-model:value="model.dmApplyCoverMethod">
                  <NRadio :value="1" label="人工" />
                  <NRadio :value="2" label="机械" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ model.dmApplyCoverMethod == 1 ? '人工' : '机械' }}</td>
            </tr>
            <tr colspan="3">
              <td colspan="3">地膜使用周期</td>
              <td class="text-center">月</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyFilmCycle" clearable :precision="0" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyFilmCycle }}</td>
            </tr>
            <tr>
              <td rowspan="6">地膜产品</td>
              <td colspan="2">厂家名称</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NInput v-model:value="model.dmApplyManufacturerName" clearable size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyManufacturerName }}</td>
            </tr>
            <tr>
              <td colspan="2">厂家电话</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NInput v-model:value="model.dmApplyManufacturerTel" clearable size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyManufacturerTel }}</td>
            </tr>
            <tr>
              <td colspan="2">地膜标识厚度</td>
              <td class="text-center">毫米</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyFilmThickness" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyFilmThickness }}</td>
            </tr>
            <tr>
              <td colspan="2">地膜标识宽度</td>
              <td class="text-center">毫米</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmApplyFilmWidth" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmApplyFilmWidth }}</td>
            </tr>
            <tr>
              <td colspan="2">地膜颜色</td>
              <td class="text-center">--</td>
              <td v-if="!isView">
                <NRadioGroup v-if="!isView" v-model:value="model.dmApplyFilmColor">
                  <NRadio :value="1" label="白色" />
                  <NRadio :value="2" label="黑色" />
                  <NRadio :value="3" label="其他" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ getDmApplyFilmColor.get(model.dmApplyFilmColor) }}</td>
            </tr>
            <tr>
              <td rowspan="8">回收方式</td>
            </tr>
            <tr>
              <td rowspan="7">回收情况</td>
              <td rowspan="2">人工捡拾</td>
              <td class="text-center">面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleManualArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleManualArea }}</td>
            </tr>
            <tr>
              <td class="text-center">成本</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleManualCost" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleManualCost }}</td>
            </tr>
            <tr>
              <td rowspan="2">机械回收</td>

              <td class="text-center">面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleMachineArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleMachineArea }}</td>
            </tr>
            <tr>
              <td class="text-center">成本</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleMachineCost" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleMachineCost }}</td>
            </tr>
            <tr>
              <td rowspan="2">复合回收（人工+机械）</td>
              <td class="text-center">面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleCompoundArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleCompoundArea }}</td>
            </tr>
            <tr>
              <td class="text-center">成本</td>
              <td class="text-center">元/亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleCompoundCost" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleCompoundCost }}</td>
            </tr>
            <tr>
              <td>不回收</td>
              <td class="text-center">面积</td>
              <td class="text-center">亩</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleNonRecycleArea" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleNonRecycleArea }}</td>
            </tr>
            <tr>
              <td colspan="4">残膜回收（离田）量</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmRecycleResidueAmount" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmRecycleResidueAmount }}</td>
            </tr>
            <tr>
              <td rowspan="5">处置情况</td>

              <td colspan="3" class="text-center">堆置田头</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposeFieldStack" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposeFieldStack }}</td>
            </tr>
            <tr>
              <td colspan="3" class="text-center">回收利用</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposeRecycle" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposeRecycle }}</td>
            </tr>
            <tr>
              <td colspan="3" class="text-center">作为农村生活垃圾处理</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposeRural" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposeRural }}</td>
            </tr>
            <tr>
              <td colspan="3" class="text-center">就近焚烧</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposeNearbyBurn" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposeNearbyBurn }}</td>
            </tr>
            <tr>
              <td colspan="3" class="text-center">就近填埋</td>
              <td class="text-center">千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.dmDisposeNearbyBury" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.dmDisposeNearbyBury }}</td>
            </tr>
            <tr>
              <td rowspan="2" colspan="2" class="text-center">废旧农膜回收站点</td>
              <td colspan="3" class="text-center">废旧农膜回收站点</td>
              <td class="text-center">有/无</td>
              <td v-if="!isView">
                <NRadioGroup v-if="!isView" v-model:value="model.wasteAgriFilmStation">
                  <NRadio :value="true" label="有" />
                  <NRadio :value="false" label="无" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ model.wasteAgriFilmStation ? '有' : '无' }}</td>
            </tr>
            <tr>
              <td colspan="3" class="text-center">回收价格</td>
              <td class="text-center">元/千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.stationRecyclePrice" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.stationRecyclePrice }}</td>
            </tr>
            <tr>
              <td rowspan="2" colspan="2" class="text-center">废旧农膜回收再企业</td>
              <td colspan="3" class="text-center">废旧农膜回收再利用企业</td>
              <td class="text-center">有/无</td>
              <td v-if="!isView">
                <NRadioGroup v-if="!isView" v-model:value="model.wasteAgriFilmEnterprise">
                  <NRadio :value="true" label="有" />
                  <NRadio :value="false" label="无" />
                </NRadioGroup>
              </td>
              <td v-else class="text-right">{{ model.wasteAgriFilmEnterprise ? '有' : '无' }}</td>
            </tr>
            <tr>
              <td colspan="3" class="text-center">回收价格</td>
              <td class="text-center">元/千克</td>
              <td v-if="!isView">
                <NInputNumber v-model:value="model.enterpriseRecyclePrice" clearable :precision="2" size="small" />
              </td>
              <td v-else class="text-right">{{ model.enterpriseRecyclePrice }}</td>
            </tr>
          </tbody>
        </table>
      </div>
      <div class="foot-info">
        <NGrid v-if="!isView" x-gap="12" :cols="4">
          <NGi>
            <NInput v-model:value="model.reportPerson" :disabled="isView">
              <template #prefix>记录人姓名：</template>
            </NInput>
          </NGi>
          <NGi>
            <NInput v-model:value="model.reportPersonContactInfo" :disabled="isView">
              <template #prefix>记录人联系方式：</template>
            </NInput>
          </NGi>
          <NGi>
            <NInput v-model:value="model.reportDate" :disabled="isView">
              <template #prefix>记录时间：</template>
            </NInput>
          </NGi>
          <NGi>
            <NInput v-model:value="model.reportUnit" :disabled="isView">
              <template #prefix>填报单位（盖章）：</template>
            </NInput>
          </NGi>
        </NGrid>
        <NSpace v-else>
          <span class="mr-60px">
            <b>记录人姓名：</b>
            {{ model.reportPerson }}
          </span>
          <span class="mr-60px">
            <b>记录人联系方式：</b>
            {{ model.reportPersonContactInfo }}
          </span>
          <span class="mr-60px">
            <b>记录时间：</b>
            {{ model.reportDate }}
          </span>
          <span>
            <b>填报单位（盖章）：</b>
            {{ model.reportUnit }}
          </span>
        </NSpace>
        <div class="h-12px"></div>
        <NInput v-if="!isView" v-model:value="model.comment" type="textarea" placeholder="备注" :disabled="isView" />
        <span v-else>
          <b>备注：</b>
          {{ model.comment }}
        </span>
      </div>
    </div>
    <template #footer>
      <NSpace v-if="!isView" justify="end">
        <NButton type="warning" @click="tempSave">临时保存</NButton>
        <NButton type="error" @click="closeModal">
          {{ $t('common.cancel') }}
        </NButton>
        <NButton type="primary" @click="handleSubmit">
          {{ $t('common.save') }}
        </NButton>
      </NSpace>
    </template>
  </NModal>
</template>

<style lang="scss" scoped>
.info {
  .title-info {
    margin-bottom: 12px;
  }

  .table-info {
    table {
      width: 100%;
      border-top: 1px solid #e5e7eb;
      border-left: 1px solid #e5e7eb;
      margin-bottom: 12px;

      th,
      td {
        border-right: 1px solid #e5e7eb;
        border-bottom: 1px solid #e5e7eb;
        padding: 5px;
      }
    }
  }
}
</style>
